package work.parabola.keyboardswitch.pojo.query.storeswitch;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import work.parabola.keyboardswitch.common.ResponseCode;
import work.parabola.keyboardswitch.common.ServerResponse;

@Data
@ToString
@EqualsAndHashCode
public class OutputQuery {

    private Integer id;

    private String amount;

    private Integer amountInt;

    public ServerResponse validate() {
        if (this.id == null) {
            return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(),
                    ResponseCode.ILLEGAL_ARGUMENT.getDesc());
        }
        if(StringUtils.isBlank(this.amount)){
            return ServerResponse.createByErrorMessage("数量错误");
        }
        try {
            this.amountInt = Integer.parseInt(this.amount);
        } catch (NumberFormatException e){
            e.printStackTrace();
            return ServerResponse.createByErrorMessage("数量错误");
        }
        if(this.amountInt.compareTo(0) <= 0){
            return ServerResponse.createByErrorMessage("出库数据不能小于0");
        }
        return ServerResponse.createBySuccess();
    }
}
